<?php
require_once("IList.php");

/**
 * Class provides the setting storage for an Embrace Model.
 * @author s.marletta
 * @version $Id: EmbraceSettings.php 6 2009-04-28 20:11:07Z embrace.toolkit $
 */
class EmbraceSettings implements IList{
	/**
	 * The list of the settings.
	 * @var Array
	 */
	private $arraySettings;

	/**
	 * Creates a new Setting Object.
	 */
	public function EmnraceSettings() {
		$this->arraySettings = Array();	
	}
	
	/**
	 * Setup the settings object.
	 * @param $xml XMLObject
	 */
	public function setup($xml) {
		$arrFromXml = $xml->xpath("/embrace_model/settings/embrace_setting");
		
		foreach($arrFromXml as $value) {
			$this->addSetting("".$value->name, "".$value->value);
		}
	}
	
	/**
	 * Adds a setting to the Setting list.
	 * 
	 * @param $settingName Name of the setting.
	 * @param $settingValue Value of the setting.
	 */
	public function addSetting($name, $value) {
		$this->arraySettings[$name] = $value;
	}
	
	/**
	 * Returns the specified setting.
	 * 
	 * @param $settingName Name of the setting.
	 * @return False if not available.
	 */
	public function getSetting($settingName) {
		if(empty($settingName))
			throw new Exception("No Settingname given.");
			
		return isset($this->arraySettings[$settingName]) ? $this->arraySettings[$settingName]: false; 
	}
	
	/**
	 * (non-PHPdoc)
	 * @see embrace/lib/IList#toArray()
	 */
	public function toArray() {
		return $this->arraySettings;
	}
}
?>